{include file='header'/}
<body>
<form class="layui-form layuimini-form" action="javascript:;" method="post" onsubmit="return dosub(this)">
    <div class="mainBox">
        <div class="main-container layui-container">
            <div class="layui-form-item">
                <label class="layui-form-label required">配置名称</label>
                <div class="layui-input-block">
                    <input type="text" id="name" name="name" value="" lay-verify="required" autocomplete="off"
                           class="layui-input" lay-reqtext="配置名称不能为空"
                           placeholder="必须是英文开头，允许带下划线和数字">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label required">配置类型</label>
                <div class="layui-input-inline">
                    <select name="fieldtype" class="select" style="width:230px" lay-filter="fieldtype">
                        <option value="text" selected>单行文本</option>
                        <option value="textarea">多行文本</option>
                        <option value="image">图片上传</option>
                        <option value="radio">radio选项卡</option>
                        <option value="select">option下拉框</option>
                        <option value="date">日期</option>
                        <option value="datetime">日期时间</option>
                        <option value="editor_mini">富文本编辑器mini</option>
                    </select>
                </div>
            </div>
            <div class="layui-form-item" style="z-index:0">
                <label class="layui-form-label required">配置值</label>

                <div class="layui-input-block upload_mode mode_text">
                    {php}echo libs\Form::text('value[text]');{/php}
                </div>

                <div class="layui-input-block upload_mode mode_textarea" style="display:none">
                    {php}echo libs\Form::textarea('value[textarea]','','例如：214243830');{/php}
                </div>


                <div class="layui-input-block upload_mode mode_image huicmf-upload" style="display:none">
                    {php}echo libs\Form::image('value[image]','','thumb-select-input',1);{/php}
                </div>

                <div class="layui-input-block upload_mode mode_radio" style="display:none">
                    <textarea name="setting[radio]" class="layui-textarea"
                              placeholder="选项用“|”分开（选项值用“:”分开【可以为空】），如“男:1|女:2|人妖:3"></textarea>
                </div>
                <tip class="upload_mode mode_radio" style="display:none">
                    选项用“|”分开（选项值用“:”分开【可以为空】），如“男:1|女:2|人妖:3”
                </tip>

                <div class="layui-input-block upload_mode mode_select" style="display:none">
                    <textarea name="setting[select]" class="layui-textarea"
                              placeholder="选项用“|”分开（选项值用“:”分开【可以为空】），如“男:1|女:2|人妖:3”"></textarea>&nbsp;
                </div>
                <tip class="upload_mode mode_select" style="display:none">
                    选项用“|”分开（选项值用“:”分开【可以为空】），如“男:1|女:2|人妖:3”
                </tip>

                <div class="layui-input-block upload_mode mode_date" style="display:none">
                    <input type="text" id="input-date" name="value[date]" autocomplete="off" value=""
                           class="layui-input" placeholder="yyyy-MM-dd">
                </div>

                <div class="layui-input-block upload_mode mode_datetime" style="display:none">
                    <input type="text" id="input-datetime" name="value[datetime]" autocomplete="off" value=""
                           class="layui-input" placeholder="yyyy-MM-dd HH:mm:ss">
                </div>

                <div class="layui-input-block upload_mode mode_editor_mini" style="display:none;">
                    {php}echo libs\Form::editorMini('value[editor_mini]','mode_editor_mini','','width:100%;height:300px',true);{/php}
                </div>

            </div>
            <div class="layui-form-item upload_mode mode_radio" style="display:none">
                <label class="layui-form-label required">默认值</label>
                <div class="layui-input-block">
                    <input type="text" name="value[radio]" class="layui-input"
                           placeholder="默认值用配置值填写（如果有: 请填写 : 后面的。如 1）">

                </div>
            </div>
            <div class="layui-form-item upload_mode mode_select" style="display:none">
                <label class="layui-form-label required">默认值</label>
                <div class="layui-input-block">
                    <input type="text" name="value[select]" class="layui-input"
                           placeholder="默认值用配置值填写">
                </div>
            </div>

            <div class="layui-form-item">
                <label class="layui-form-label">简洁说明</label>
                <div class="layui-input-block">
                    <input type="text" id="title" name="title" autocomplete="off" class="layui-input"
                           placeholder="例如：这个是站点QQ">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">是否启用</label>
                <div class="layui-input-block" id="status">
                    <input type="radio" name="status" value="1" title="启用" checked>
                    <input type="radio" name="status" value="0" title="禁用">
                </div>
            </div>

        </div>
    </div>
    <div class="bottom">
        <div class="button-container">
            <button class="pear-btn pear-btn-primary pear-btn-sm" lay-submit="">
                <i class="layui-icon layui-icon-ok"></i>
                提交
            </button>
            <button type="reset" class="pear-btn pear-btn-sm">
                <i class="layui-icon layui-icon-refresh"></i>
                重置
            </button>
        </div>
    </div>
</form>

{include file='footer'/}
<script>
  layui.use(['layer', 'jquery', 'form', 'laydate'], function () {
    var layer = layui.layer,
      $ = layui.jquery,
      form = layui.form,
      laydate = layui.laydate;

    laydate.render({
      elem: '#input-date'
      , type: 'date'
    });

    laydate.render({
      elem: '#input-datetime'
      , type: 'datetime'
    });


    form.on('select(fieldtype)', function (data) {
      $('.upload_mode').hide();
      $('.mode_' + data.value).show();
    });

    //保存
    window.dosub = function (obj) {
      var reg = /^[a-zA-Z]{1}([a-zA-Z0-9]|[_]){0,19}$/;
      if (obj.name.value.length < 1 || obj.name.value.length > 20) {
        layer.msg('配置名称长度必须为1-20位！', {icon: 2});
        return false;
      }
      if ($("input[name='name']").val() == '' || !reg.test($("input[name='name']").val())) {
        layer.msg('配置名称必须为英文拼音数字_！', {icon: 2});
        return false;
      }
      $.ajax({
        type: 'POST',
        url: "{:url('config/customConfigAdd')}",
        data: $(obj).serialize(),
        dataType: "json",
        success: function (res) {
          if (res.code === 200) {
            layer.msg(res.msg, {icon: 1, time: 2000}, function () {
              window.location.reload();
            })
          } else {
            layer.msg(res.msg, {icon: 2, time: 2000})
          }
        }
      });
    }
  });
</script>
</body>
</html>
